package com.qyer.search.model.aggregation;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Created by tangzheng on 16/7/17.
 */
public class VStype implements Comparable<VStype>{

  @JsonProperty
  private int id;
  @JsonProperty
  private String name;
  @JsonProperty
  private int size;

  public VStype(int id, String name) {
    this.id = id;
    this.name = name;
  }

  public VStype(int id, String name, int size) {
    this.id = id;
    this.name = name;
    this.size = size;
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }


  public int getSize() {
    return size;
  }

  public void setSize(int size) {
    this.size = size;
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    VStype vStype = (VStype) o;

    return id == vStype.id;

  }

  public void incSize(){
    size++;
  }

  @Override public int hashCode() {
    return id;
  }

  @Override public int compareTo(VStype vStype) {
    return (vStype.getSize() - this.size);
  }

  public void add(VStype vStype){
    if(this.name.equals(vStype.getName())){
      this.size += vStype.getSize();
    }
  }
}
